What is the TurboCAD SDK and what can it do for me ?
What do I need to know to use C++, Delphi, Java or Visual Basic to build a TurboCAD SDK application. ?
How do I connect to TurboCAD with OLE ?:
How do I load and display a TurboCAD drawing ?
How do I draw a graphic on screen ?
How do I select a graphic object ?
How do I zoom a drawing ?
How do I Pan the drawing ?
The following tree show the typical outline structure for using the SDK:
*A container is a collection of objects such as Drawings, Graphics, Views, Properties,
C++: The
code can be written in any C++ product or classes such as MFC,
Win32 SDK, C++Builder, Optima++.
The main application interface for the SDK
is IApplicaton. The interface methods and
properties can be used as listed
in the SDK reference.
Reference counts are handled manually in C++. You must use
the AddRef() and release() method to properly access and release
connection to the TurboCAD server for an object. If you obtain an
object from a property call (get_Graphics(...)) the AddRef() has
been called already. You only need to release() it when done. See
the example for coding details.
Delphi: Delphi
has a built-in interface to OLE which can easily implement the use
of the SDK. Delphi uses the Variant class (see Variant in Delphi
help) to pass all information between the Delphi Client and the
Server (TurboCAD SDK). When referring to the SDK methods and
properties, property names will
be translated in Delphi in the following manner:
put_PropertyName(...)
is translated
to PropertyName :=
prop
EXAMPLE:
HRESULT View::put_ScreenLeft(double* prop )
( from C++ method reference)
is translated to
View.ScreenLeft :=
sLeft;
(sLeft is a double)
Methods are accessed as any procedure
or function in Delphi
InterfaceName.ProcedureName
or InterfaceName.FunctionName(...)
EXAMPLE:
View.refresh;
Java: Microsoft has created a COM interface for Java,
which is in built-in to Internet Explorer and VM (JView). To
program using the interface you must first run the Java TypeLib
Wizard (J++ Tools) program on the 'TurboCAD 4.0 Type Library'.
This will create a group of Java classes ('trusted', which means
either they must be signed (CAB) or the application files placed
on the CLASSPATH) which can be used to access the IMSI
SDK.
When referring to the IMSI SDK methods and
properties, (or the Java IMSI
classes) property names will be
translated in Java in the following manner:
put_PropertyName(...)
is translated
to
putPropertyName(...)
EXAMPLE:
HRESULT View::put_ScreenLeft(double* prop )
( from C++ method reference)
is translated to
View.putScreenLeft(double prop);
Methods from the SDK classes are
accessed as any method call using the interface as the
class.
EXAMPLE:
View.Refresh();
Visual
Basic: When referring to the SDK
methods
and properties, property names
will be translated in Visual Basic in the following manner:
put_PropertyName(...) is translated to PropertyName =
prop
EXAMPLE:
HRESULT View::put_ScreenLeft(double* prop )
( from C++ method reference)
is translated to
View.ScreenLeft = sLeft
(sLeft is a double)
EXAMPLE:
Drawing.Graphics.Properties("PenColor") =
123
Methods are accessed as any procedure
or function in Delphi
InterfaceName.ProcedureName
or
InterfaceName.FunctionName(...)
EXAMPLE:
View.refresh
#include <gxintf.h> #include <imsigx.h> ... const CLSID CLSID_XApplication = {0x6A481801,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}}; IApplication *pIApplication = 0; ... HRESULT hRes = CoCreateInstance ( CLSID_XApplication, // Class identifier (CLSID) of the object NULL, // Object is or isn't part of an aggregate CLSCTX_INPROC_SERVER, // Context for running executable code IID_IApplication, // Interface identifier (void**)&pIApplication // Points to requested interface pointer ); if (FAILED(hRes)) // check for errors that are return from the method call (ie. CoCreateInstance) { // do something to handle error }
var SDKApp: Variant; ... try { Here the application connects with the IMSIGX40.dll OLE server } SDKApp := CreateOleObject('IMSIGX.Application'); except on E:Exception do { Errors are returned to Delphi from OLE by Exceptions } { handle exception }
// IMSI Application COM Interface variable public imsigx40.IApplication m_IApp=null; try // all error returned from COM interaction are through Exceptions { /* first connect to application server. imsigx40.XApplication must be used to connect to the inproc_server IMSIGX40.DLL. If you wish to connect to the local server TC40.exe use imsigx40.Application. Make sure to cast the classes XApplication and Application to IApplication. This is required by the Microsoft Java/OLE implementation (classes must be casted to an interface). For further discussion check Microsoft's web docs Using a COM Object From Java (OLE) or your J++ documentation. Also due to the conflict between Java and IMSI class names we cannot import the IMSI SDK directly using import imsigx40.* but must use the full Java classpath with names (ie. imsigx40.IApplication) as seen below. */ m_IApp = (imsigx40.IApplication) new imsigx40.XApplication(); } catch (com.ms.com.ComException e) { // handle error }
Dim theApplication As Object 'Application object ... Private Sub Form_Load() 'Set up error handling. All errors from the SDK or OLE will be handled by this statement On Error GoTo CatchError 'Open the application Set theApplication = CreateObject("IMSIGX.Application") ... Exit Sub CatchError: 'Handle Error End Sub
The following code illustrates how to
load and display a drawing. You must first connect to a
application, which is discussed in How do I connect to TurboCAD
with OLE. After connecting to
the application you obtain a container to hold one or more
drawings. With a interface handle to the container, we can then
add or open drawings.
C++:
// see How do I connect to TurboCAD with OLE for C++ Drawings* pDrawings = NULL; // Pointer to Drawings collection HRESULT hRes = pIApplication->get_Drawings(&pDrawings); // Get the handle to the drawings collection. (returned as pointer) if (FAILED(hRes)) return; IDrawing* pIDrawing = NULL; // Pointer to drawing object VARIANT var; // Make a "missing" optional parameter var.vt = VT_ERROR; var.scode = DISP_E_PARAMNOTFOUND; CString strPath = GetAFileName(); // Call routine to get a file from dialog or whereever BSTR bstrPath = strPath.AllocSysString(); // We must put the file name into a OLE BSTR hRes = pDrawings->Open(bstrPath, &var, &var, &pIDrawing); // Add the drawing to the drawings collection ::SysFreeString(bstrPath); // Free the system memory for the BSTR if (SUCCEEDED(hRes)) // We now make the SDK draw to the screen { hRes = pIDrawing->get_Views(&pViews); // get the Views collection for the drawing if (FAILED(hRes)) return; hRes = pViews->Add(&var, &var, &pView); // Add a view to the collection if (FAILED(hRes)) return; pView->put_Update(FALSE); // postpone update of screen until refresh() pView->put_HWND(long(hwnd)); // set the window handle to paint on pView->put_MappingMode(long(MM_TEXT)); pView->put_ScreenLeft(double(x)); // Set the left, top, width and height of screen pView->put_ScreenTop(double(y)); pView->put_ScreenWidth(double(w)); pView->put_ScreenHeight(double(h)); pView->put_FixedAspectRatio(TRUE); // keep aspect ratio pView->ZoomToExtents(); // ZoomToExtents finds the largest bounding box of drawing and zooms to these pView->Refresh(); // call SDK refresh, which repaints the window pIDrawing->Release(); // Finished with drawing object, decrement reference count } else // do somthing to handle error { } // Finished with drawings collection, decrement reference count pDrawings->Release();
Delphi:
// see How do I connect to
TurboCAD with OLE from Delphi
for OLE connection information.
TheDrawing := SDKDrawings.Open(FileName); // Open drawing file SDKViews := TheDrawing.Views; // Get a Views container (collection) TheView := SDKViews.Add(); // Add a View to the Views collection TheView.Update := False; { Delay update until we tell it to. } CanvasDC := PaintBox1.Canvas.Handle; { Obtain the Device Context for the PaintBox canvas. } TheView.DC := CanvasDC; TheView.MappingMode := MM_TEXT; TheView.FixedAspectRatio := TRUE; TheView.Margins := FALSE; { set up so that margins are not used, otherwise redraw will shrink } TheView.ScreenLeft := 0.0; TheView.ScreenTop := 0.0; TheView.ScreenWidth := PaintBox1.Width; { use width of the window we are painting on } TheView.ScreenHeight := PaintBox1.Height; { use height of the window we are painting on } TheView.ZoomToExtents; { zoom to largest drawing area of drawing } ViewLeft := TheView.ViewLeft; { get back View rectangle in Drawing coordinate system (inch, mm, points ...} ViewTop := TheView.ViewTop; ViewWidth := TheView.ViewWidth; ViewHeight := TheView.ViewHeight; TheView.refresh; ( tell the SDK to refresh the screen (redraws whole window or clipped region if you set a different clipped rectangle )
Java:
(currently implemented only for
Internet Explorer)
// see How do I connect to
TurboCAD with OLE from Java
for OLE connection information.
imsigx40.Drawings m_IDrawings=null; imsigx40.IDrawing m_ITheDrawing=null; imsigx40.Views m_IViews=null; imsigx40.View m_ITheView=null; com.ms.com.Variant nParam = new com.ms.com.Variant(); // Create a Variant for an optional parameter nParam.noParam(); // Set the Variant for no parameter m_IDrawings = (imsigx40.Drawings) m_IApp.getDrawings(); // METHOD -- imsigx40.IDrawing Open(java.lang.String, com.ms.com.Variant [optional], com.ms.com.Variant [optional]); m_ITheDrawing = (imsigx40.IDrawing) m_IDrawings.Open(m_fileName, nParam, nParam); // method -- imsigx40.Views getViews(); // we now get the views collection for this drawing m_IViews = (imsigx40.Views) m_ITheDrawing.getViews(); // Class METHOD -- imsigx40.View Add(com.ms.com.Variant [optional], com.ms.com.Variant [optional]); m_ITheView = (imsigx40.View) m_IViews.Add(nParam, nParam); // add a new view to the views collection for drawing byte b = 0; // to pass a boolean use a byte with 0=false, 1=true m_ITheView.putUpdate(b); // delay update until we tell it to refresh m_ITheView.putHWND(CompHwnd); m_ITheView.putMappingMode(1); // We don't want margins as this will redraw with a margin every redraw, which // using the same screen coordinates, will shrink the screen. b = 0; // to pass a boolean use a byte with 0=false, 1=true m_ITheView.putMargins(b); b = 1; // set to same aspect ratio m_ITheView.putFixedAspectRatio (b); m_ITheView.putScreenLeft(0.0); m_ITheView.putScreenTop(0.0); m_ITheView.putScreenWidth(rec.width); m_ITheView.putScreenHeight(rec.height); m_ITheView.ZoomToExtents(); // zoom to the largest extents of the drawing. m_ITheView.Refresh(); // call the SDK's Refresh method.
Visual
Basic:
// see How do I connect to TurboCAD
with OLE from Visual Basic
for OLE connection information.
Set theDrawing = theApplication.Drawings.Add("Normal") ' Add with Normal template Set theDrawing = theApplication.Drawings.Open(SomeFileName.tcw) Set theView = theDrawing.Views.Add(Me.hWnd) ' This creates a view and sets the window handle theView.ViewHeight = Frame1.Height ' Height of drawing window theView.ViewWidth = Frame1.Width theView.ViewTop = Frame1.Top theView.ViewLeft = Frame1.Left theView.ZoomToExtents theView.Refresh
Please refer to How do I connect to TurboCAD
with OLE for information on
the first step in drawing a graphic on screen.
The general procedure for drawing a graphic
on the screen is:
- First create or loaded a drawing see: How do I load and display a TurboCAD drawing
- From the Drawing handle get a Graphics container.
- From the Graphics container add a Graphic. This could be a point, line, circle or any number of different objects.
- Redraw the screen.
Please refer to How do I connect to TurboCAD
with OLE for information on
the first steps in drawing a graphic on screen.
The general procedure for selecting (pick) a
graphic object is:
- Obtain a View for the Drawing . see: How do I load and display a TurboCAD drawing.
- With the View handle use one of the View object methods: PickPoint, PickRect or PickPolygon.
- This will return a PickResult which is an object containing one or more graphic object.
- Using the get_Count and get_Item you can cycle through these objects and operate on them in some manner (change properties, delete object, change verticies , etc).
Please refer to How do I connect to TurboCAD
with OLE for information on
the first steps in drawing a graphic on screen.
Zooming requires changing the View prospective of the drawing.
Zooming -in requires decreasing the ViewWidth and ViewHeight as
compared to the ScreenWidth and ScreenHeight. Zooming out does the
opposite.
The general procedure for zooming in and out is as follows:
- Obtain a View for the drawing . see: How do I load and display a TurboCAD drawing.
- Change the ViewLeft, ViewTop, ViewWidth, ViewHeight properties to decrease (zoom in) or increase (zoom out) in size.
- With the View handle call, which will display the drawing to the limits of the View coordinates.
Please refer to How do I connect to TurboCAD
with OLE for information on
the first steps in drawing a graphic on screen.
Panning requires changing the View prospective of the drawing.
This requires shifting the ViewLeft or ViewTop as compared to the
ScreenLeft and ScreenTop.
The general procedure for panning is as follows:
- Obtain a View for the drawing . see: How do I load and display a TurboCAD drawing.
- Change the ViewLeft, ViewTop properties to shift left or right.
- With the View handle call refresh(), which will move the drawing to the View coordinates.
SDK Top API Reference TurboCAD Home Page TurboCAD Programming Forums